﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MotoGame.Core
{
    class Message
    {
        #region Fields & Properties
        int time;

        int lifetimeInMillis;
        public int LifetimeInMillis
        {
            get { return lifetimeInMillis; }
            set { lifetimeInMillis = value; }
        }

        string text;
        public string Text
        {
            get { return text; }
            set 
            {
                time = 0; // restart timer;
                text = value;
            }
        }

        SpriteFont font;
        public SpriteFont Font
        {
            get { return font; }
            set { font = value; }
        }

        Vector2 position;
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        Color foreground;
        public Color Foreground
        {
            get { return foreground; }
            set { foreground = value; }
        }
        #endregion

        #region Constructors
        public Message(Game game)
        {
            Font = game.Content.Load<SpriteFont>("arial");
            LifetimeInMillis = 2000;
            Position = Vector2.Zero;
            Foreground = Color.Red;
            Text = "";
        }
        #endregion

        #region Operations
        public void Update(GameTime gameTime)
        {
            time += gameTime.ElapsedGameTime.Milliseconds;

            if (time > LifetimeInMillis)
            {
                Text = "";
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(Font, Text, Position, Foreground);
        }
        #endregion
    }
}
